//
//  Status.swift
//  WeoboWithSteveLi
//
//  Created by SteveLi on 2017/10/5.
//  Copyright © 2017年 李军桦. All rights reserved.
//

import UIKit
/// 微博数据模型
class Status: NSObject {
    /// 微博ID
    var id: Int = 0
    /// 微博信息内容
    var text: String?
    /// 微博创建时间
    var created_at: String?
    /// 微博来源
    var source: String?
    /// 缩略图配图数组
    var pic_urls: [[String:String]]?
    /// 用户模型
    var user: User?
    //被转发的原微博信息字段，当该微博为转发微博时返回
    var retweeted_status: Status?
    init(dict: [String: Any]) {
        super.init()
        //如果使用 kvc 时，value是一个字典，会直接给属性转换成字典
        setValuesForKeys(dict)
    }
    
    override func setValue(_ value: Any?, forKey key: String) {
        //判断 key 是否是user
        if key == "user" {
            if let dict = value as? [String :Any] {
                user = User(dict: dict)
            }
            return
        }
        //判断 key 是否是 retweeted_status
        if key == "retweeted_status" {
            if let dict = value as? [String: AnyObject] {
                retweeted_status = Status(dict: dict)
            }
            return
        }
        
        super.setValue(value, forKey: key)
    }
    override func setValue(_ value: Any?, forUndefinedKey key: String) {}
    //override func setValue(_ value: Any?, forKey key: String) {}
    override var description: String {
        let keys = ["id","text","created_at","source","user","pic_urls","retweeted_status"]
        return dictionaryWithValues(forKeys: keys).description
    }
}



